<?php include('header.php');
include('menu.php');
include('config.php');
$loginid=$_SESSION['loginid'];

?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<title>Compose</title>
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
</head>
<body>
<font face="Verdana" style="font-size: 8.5pt">
<?php
if (isset($_POST['submit']))
{


	$user_type=$_POST['usertype'];
	if($user_type=="ALL") $qry = "select login_id from tbl_lookup_user where login_id != '$loginid'";
	else $qry = "select login_id from tbl_lookup_user where user_type = '$user_type' and login_id != '$loginid' ";
	
	$res1=mysql_query($qry);

	$subject = $_POST['subject']; 
	$message = $_POST['message'];

	while($user=mysql_fetch_assoc($res1))	
	{
    	 $e=$user['login_id'];	  
	
	$qr="INSERT INTO tbl_dtls_compose(id, user_type, receiver, sender, sub, message, post_time) VALUES(NULL, '$user_type', '$e', '$loginid', '$subject', '$message', NOW())";
	//echo $qr;
	$r5=mysql_query($qr);	
	}
	
	if(mysql_affected_rows() > 0)
	{	
		echo'<span class="successmssg"><b>Congratulation!!</b><br/>Your mail is Successfully Sent. Now you can go on <a href="home.php">home</a> page or <a href="communication.php">Compose Mail</a> again. </span>';
		
	}
	else 
	{		//echo "Some problem inserting record";
		echo'<h3>Sorry, some error occured, please try again after sometime.<h3>';
	}
	
}
?>
</font>
<form action="" method="post" name="compose" id="compose" onSubmit="return compose123()">
<table border="0" width="78%" id="table21" height="51%" cellspacing="1" cellpadding="1" style="padding:10px;">
<tr  bgcolor="#eeeeee">
	<td height="26" colspan="3" bgcolor="#C5D8EB" align="center"><font style="font-size: 8.5pt" face="Verdana" color="#006699"><b>Compose Mail</b></font></td>
</tr>	
<tr bgcolor="#eeeeee">
	<td height="26" colspan="3" >&nbsp;</td>
</tr>		
<tr bgcolor="#eeeeee">
	<td width="203" height="26">&nbsp;</td>
	<td valign="top"><font style="font-size: 8.5pt" face="Verdana" color="#000000"><b>User type</b></font></td> 
	<td width="641" valign="top"><font face="Verdana">
			<select  name="usertype" id="usertype" style="font-size: 8pt; font-family: Verdana; border:1px solid black;  border-width: 1px">
			<option selected value="0">Select User Type</option>													
				<?php	foreach($type as $key=>$val)
				{
		  			 echo "<option value=$key>$val</option>";
	  			 }
				?>
				<option value="ALL">All</option>
		</select>
						</font>
	  </td></tr>
	<tr bgcolor="#eeeeee">
		<td width="203" height="27">&nbsp;</td>
		<td width="137" valign="top"><font style="font-size: 8.5pt" face="Verdana" color="#000000"><b>Subject</b></font></td>
		<td valign="top"><font face="Verdana">
			<input type="text" name="subject" id="subject" size="44" style="font-size: 8pt; font-family: Verdana; border:1px solid black;  border-width: 1px"></font>	</td></tr>
		<tr bgcolor="#eeeeee">
		<td width="203" height="104">&nbsp;</td>
		<td width="137" valign="top">								
		<font face="Verdana" style="font-size: 8.5pt" color="#000000"><b>Message</b></font></td>
		<td valign="top"><font face="Verdana"><span style="font-size: 8.5pt">
		<textarea name="message" cols="42" rows="8"  class="input" id="message" style="font-size: 8pt; font-family: Verdana; border:1px solid black;  border-width: 1px"></textarea></span></font></td></tr>
			<tr bgcolor="#eeeeee">
				<td width="203" height="24">&nbsp;</td>
				<td width="137">&nbsp;</td>
				<td><input type="submit" value="Send" name="submit" style="border:1px solid #000000; font-size: 8pt; font-family: Verdana; ">														</td></tr>
</table>
</form>
					

</body>	
</html>
                 
